#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
using namespace std;

namespace my
{
	class string
	{
	public:
		string(const char* str = "");
		string(const string& s);
		string& operator=(const string& str);
		
		~string()
		{
			delete[] _str;
		}

		const char* c_str() const
		{
			return _str;
		}

		char& operator[](size_t i)
		{
			assert(i < _size);

			return _str[i];
		}

		const char& operator[](size_t i) const
		{
			assert(i < _size);

			return _str[i];
		}

		size_t size() const
		{
			return _size;
		}

		size_t capacity() const
		{
			return _capacity;
		}

		void reserve(size_t n = 0);
		void resize(size_t n);
		void append(const char* s);
		void push_back(char c);
		void clear();
		bool empty() const;

		string& operator+=(const char* s);
		string& operator+=(char c);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);
		string substr(size_t pos = 0, size_t len = npos) const;

		size_t find(char ch, size_t pos = 0) const;
		size_t find(const char* str, size_t pos = 0) const;

		void swap(string& s);

	private:
		char* _str;
		size_t _size;
		size_t _capacity;

	public:
		static const size_t npos;
	};

	void swap(string& x, string& y);
	bool operator== (const string& lhs, const string& rhs);
	bool operator!= (const string& lhs, const string& rhs);
	bool operator> (const string& lhs, const string& rhs);
	bool operator< (const string& lhs, const string& rhs);
	bool operator>= (const string& lhs, const string& rhs);
	bool operator<= (const string& lhs, const string& rhs);

	ostream& operator<<(ostream& os, const string& str);
	istream& operator>>(istream& is, string& str);
	istream& operator>>(istream& is, string& str);
	istream& getline(istream& is, string& str, char delim = '\n');
}